<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    canvas {
      border: 2px solid red;
    }
  </style>
</head>
<body>
  <canvas height="400px" width="600px"></canvas>
</body>
<script>
  const canvas = document.querySelector('canvas')
  var ctx = canvas.getContext('2d');
  
  //绘制矩形
  ctx.fillRect(100,100,150,150)
  //清除画布
  /* ctx.clearRect(0,0,400,600) */
  //清除部分画布
  ctx.clearRect(100,100,50,50)
  
  //设置文字大小
  ctx.font = '20px 微软雅黑'
  ctx.fillStyle = 'red'
  //绘制文字
  ctx.fillText('你好呀',300,100)
</script>
</html>